import 'package:bloctest/pages/hot_page/hot_presenter.dart';
import 'package:bloctest/utils/base/BasePresenter.dart';
import 'package:bloctest/utils/base/LifeCyclePage.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:bloctest/model/hotkey_model.dart';

class HotPage extends LifeCyclePage {
  const HotPage({super.key});

  @override
  HotPageState createState() => HotPageState();
}

class HotPageState extends LifeCyclePageState<HotPage> {
  List<HotkeyItem> topList = [];
  List<HotkeyItem> urlList = [];


  @override
  Map<String, dynamic> get getLoadDataParams => <String, dynamic>{};

  @override
  Widget build(BuildContext context) {
    return SafeArea(
        child: SingleChildScrollView(
      scrollDirection: Axis.vertical,
      child: Container(
        padding: EdgeInsets.all(10.r),
        child: Column(
          children: [
            getGridWidget(topList),
            textLine(),
            SizedBox(
              height: 20.h,
            ),
            getGridWidget(urlList)
          ],
        ),
      ),
    ));
  }

  @override
  HotPagePresenter createPresenter() => HotPagePresenter(this);

  @override
  // TODO: implement presenter
  HotPagePresenter get presenter => super.presenter as HotPagePresenter;
}

Widget textLine() {
  return Container(
    width: double.infinity,
    padding: EdgeInsets.only(top: 20.h, bottom: 20.h),
    decoration: BoxDecoration(
        border: Border(bottom: BorderSide(width: 1.w, color: Colors.black))),
    child: const Text("常用网站"),
  );
}

Widget getGridWidget(List<HotkeyItem> list) {
  return GridView.builder(
      gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
          maxCrossAxisExtent: 120.w,
          mainAxisSpacing: 10.w,
          crossAxisSpacing: 10.w,
          childAspectRatio: 2.5),
      // 子项的宽高比
      itemCount: list.length,
      shrinkWrap: true,
      physics: const NeverScrollableScrollPhysics(),
      itemBuilder: (context, index) {
        return getItem(list[index]);
      });
}

Widget getItem(HotkeyItem item) {
  return InkWell(
    onTap: () {},
    child: Container(
      decoration: BoxDecoration(
          border: Border.all(width: 1.w, color: Colors.blueGrey),
          borderRadius: BorderRadius.all(Radius.circular(6.r))),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Text(
            item.name ?? "",
            maxLines: 1,
            overflow: TextOverflow.ellipsis,
          )
        ],
      ),
    ),
  );
}
